<?php
/**
* Load statistic data on the transactions overview
*
* @author       Fabrice Douteaud <admin@clearbudget.net>
* @package      actions
* @access       public
*/

/***********************************************************************

  Copyright (C) 2008  Fabrice Douteaud (admin@clearbudget.net)

    This file is part of ClearBudget.

    ClearBudget is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    ClearBudget is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with ClearBudget.  If not, see <http://www.gnu.org/licenses/>.


************************************************************************/
//prevent direct access
if(!defined('ENGINEON')) die('Direct access forbidden');

$report = class_report::getInstance();
$report->getData();
if($report->validData === false) {
  global $context;
  $context->error = 'error_NoTransactionData';
  $context->redirect('errorDisplay');
  return;
  }
$dates = $report->dates;
$debits = $report->debitTotalPerMonth;
$credits = $report->creditTotalPerMonth;
$totalDebits = $report->totalDebits;
$totalCredits = $report->totalCredits;


$debitsPctPerMonth = $report->debitPctPerMonth;
$creditsPctPerMonth = $report->creditPctPerMonth;
$debitPerCategoryPerMonth = $report->debitPerCategoryPerMonth;
$creditPerCategoryPerMonth = $report->creditPerCategoryPerMonth;
$debitTotalPerMonth = $report->debitTotalPerMonth;
$creditTotalPerMonth = $report->creditTotalPerMonth;
$debitTotalPerCategory = $report->debitTotalPerCategory;
$categories = $report->categories;
$categoryColor = $report->categoryColor;

// Overall credit vs debit graph
$creditPct = $report->formatNumber($report->totalCredits/($report->totalDebits+$report->totalCredits) * 100);
$debitPct = $report->formatNumber($report->totalDebits/($report->totalDebits+$report->totalCredits) * 100);
$chart = new GoogleChart('p3', $keys->graphTitle_overallDebitsVsCredits, 500, 200);
$chart->addLegend($debitPct.'%');
$chart->addValue($debitPct);
$chart->addColor('FF2725');
$chart->addLegend($creditPct.'%');
$chart->addValue($creditPct);
$chart->addColor('97EE14');
$url1 = $chart->getURL();

// monthly spending VS credits
$chart = new GoogleChart('bvs', $keys->graphTitle_monthlyDebitsVsCredits, 400, 150);
$chart->addColor('97EE14');
$chart->addColor('FF2725');
$chart->addLegend($keys->text_Credit);
$chart->addLegend($keys->text_Debit);
foreach($dates as $date) {
  $month = explode('-', $date);
  $chart->addxAxis($month[0]);
  }
foreach($creditTotalPerMonth as $month=>$credit) {
  @$chart->addValue($credit/($debitTotalPerMonth[$month]+$credit) * 100);
  }
$chart->addValueSerie();
foreach($debitTotalPerMonth as $month=>$debit) {
  @$chart->addValue($debit/($creditTotalPerMonth[$month]+$debit) * 100);
  }
$chart->addyAxis('0|20|40|60|80|100');
$url2 = $chart->getURL();

?>